﻿using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.ShouFeiGL
{
    public partial class JiuQianTS_ZJ : BasePage
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        /// 记录查询结果集2
        /// </summary>
        private DataTable dtSource2
        {
            get
            {
                return ViewState["dtSource2"] as DataTable;
            }
            set
            {
                ViewState["dtSource2"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 收费BLL
        /// </summary>
        YS_SF_SHOUFEIBLL _YS_SF_SHOUFEIBLL = new YS_SF_SHOUFEIBLL();

        /// <summary>
        /// 托收明细对象
        /// </summary>
        YS_SF_TUOSHOUMX _YS_SF_TUOSHOUMX = new YS_SF_TUOSHOUMX();

        /// <summary>
        /// 托收明细BLL
        /// </summary>
        YS_SF_TUOSHOUMXBLL _YS_SF_TUOSHOUMXBLL = new YS_SF_TUOSHOUMXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitailControl();
               
                this.txtYongHuH.Focus();
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 加载控件
        /// </summary>
        private void InitailControl()
        {
            //获取收费信息
            //string shoufeiBH = this.Request["sfbh"];
            //生成新的进账单 else:添加明细
            this.txtShouFeiBH.Text = "0";
            DataTable dt = _spHelper.P_QSSF_JQTS(1, null, null, null).Tables[0];
            if (dt.Rows.Count > 0)
            {
                this.txtZongBiS.Text = dt.Rows[0]["ZBS"].ToString();
                this.txtZongJinE.Text = dt.Rows[0]["ZJE"].ToString();
            }
            else
            {
                this.txtZongBiS.Text = "0";
                this.txtZongJinE.Text = "0.00";
            }



            //加载默认数据
            //this.txtJinE.Text = "0.00";

        }

        #endregion

        #region 事件

        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int sflx = cmbSFLX.Text != "" ? Convert.ToInt32(cmbSFLX.Value) : 0;
            string yhh = txtYongHuH.Text;
            int ym = Convert.ToInt32(txtYM.Text);
            string msg = "";
            if (e.Parameter == "search")
            {
                //验证当前用户在该水量年月是否欠费， 
                DataTable dt = _spHelper.P_QSSF_JQTS(2, sflx, yhh, ym).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    string res = dt.Rows[0][0].ToString();
                    if (res == "0")
                    {
                        msg = res;
                    }
                    else //验证通过后获取数据并显示
                    {
                        msg = string.Join("|", dt.Rows[0]["S_YONGHUH"].ToString(), dt.Rows[0]["N_KAIZHANGJE"].ToString(),
                            dt.Rows[0]["S_KAIHUHM"].ToString(), dt.Rows[0]["S_KAIHUH"].ToString(), dt.Rows[0]["S_KAIHUYH"].ToString()
                            );
                    }
                }

            }
            else if (e.Parameter == "SaveData")
            {
                //将页面数据添加进数据库 ，银行批量代理
                decimal zje = txtZongJinE.Text != "" ? Convert.ToDecimal(txtZongJinE.Text) : 0;
                int zbs = txtZongBiS.Text != "" ? Convert.ToInt32(txtZongBiS.Text) : 0;

                decimal je = txtJinE.Text != "" ? Convert.ToDecimal(txtJinE.Text) : 0;
                string khhm = txtKaiHuHM.Text;
                string yhzh = txtKaiHuZH.Text;
                string khyh = txtKaiHuYH.Text;
                DataTable dt = _spHelper.P_QSSF_JQTS_SCSJ(yhh, ym, khhm, yhzh, khyh, je, zje, zbs).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    msg = dt.Rows[0][0].ToString();
                }
            }
            e.Result = e.Parameter + "|0|" + msg;
        }
        #endregion

       
    }
}